package com.zego.wawaji.ui.coupon.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.zego.wawaji.base.data.BaseData;
import com.noble.library.basic.string.StringUtils;

import org.json.JSONObject;

/**
 * 优惠券
 * Created by Su on 2018/2/24.
 */
public class Coupon extends BaseData implements Parcelable {
    private long couponId;      // 优惠券id
    private int couponStatus;   // 优惠券状态  -2: 过期  -1： 已使用  1：可使用
    private String expireTime;  // 过期时间
    private int amount;         // 充值满多少可使用
    private int wwCoinZs;       // 赠送娃娃数量
    private String remark;      // 优惠券描述信息
    private String title;       // 优惠券标题

    @Override
    public void parseJson(String jsonStr) {
        JSONObject jsonObject = getJsonObject(jsonStr);

        this.couponId = jsonObject.optLong("Id");
        this.couponStatus = jsonObject.optInt("CouponStatus");
        this.expireTime = jsonObject.optString("ExpireTime");
        this.amount = jsonObject.optInt("Amount");
        this.wwCoinZs = jsonObject.optInt("WwCoinZs");
        this.remark = jsonObject.optString("Remark");
        this.title = jsonObject.optString("Title");
    }

    public long getCouponId() {
        return couponId;
    }

    public int getCouponStatus() {
        return couponStatus;
    }

    public String getExpireTime() {
        return StringUtils.getCreateTime(expireTime);
    }

    public int getAmount() {
        return amount;
    }

    public int getWwCoinZs() {
        return wwCoinZs;
    }

    public String getRemark() {
        return remark;
    }

    public String getTitle() {
        return title;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.couponId);
        dest.writeInt(this.couponStatus);
        dest.writeString(this.expireTime);
        dest.writeInt(this.amount);
        dest.writeInt(this.wwCoinZs);
        dest.writeString(this.remark);
        dest.writeString(this.title);
    }

    public Coupon() {
    }

    protected Coupon(Parcel in) {
        this.couponId = in.readLong();
        this.couponStatus = in.readInt();
        this.expireTime = in.readString();
        this.amount = in.readInt();
        this.wwCoinZs = in.readInt();
        this.remark = in.readString();
        this.title = in.readString();
    }

    public static final Creator<Coupon> CREATOR = new Creator<Coupon>() {
        @Override
        public Coupon createFromParcel(Parcel source) {
            return new Coupon(source);
        }

        @Override
        public Coupon[] newArray(int size) {
            return new Coupon[size];
        }
    };
}
